<?php
/**
 * 网点公众号权限控制
 */
namespace soa\mp\shop;

use soa\client;

class authority  extends client
{
	private static $_authorityArr = [
		"3" => ["cloud_print" => true,],
		"5" => ["cloud_print" => true,],
		"36" => ["cloud_print" => true,],
	];

	private static function _getAuthority($id){
		return self::$_authorityArr[$id] ? : [];
	}

	public static function getIdByState($state){
		if(!is_string($state)){
			return null;
		}
		$state = str_replace("weixin_shop_","",$state);
		return preg_match('/^\d+$/',$state) ? intval($state) : null;
	}

	public static function getStateById($id){
		return is_string($id) && !preg_match('/^\d+$/',$id) ? "weixin_shop_" . $id : null;
	}

	public static function getServicesByState($state){
		$id = self::getIdByState($state);
		if(!empty($id)){
			return self::_getAuthority($id);
		}
		return null;
	}

	public static function getServicesById($id){
		if(!empty($id)){
			return self::_getAuthority($id);
		}
		return null;
	}

	public static function verifyByState($state,$service){
		$ret = self::getServicesByState($state);
		return !empty($ret) && isset($ret[$service]) && !empty($ret[$service]) ?  true : false;
	}

	public static function verifyById($id,$service){
		$ret = self::getServicesById($id);
		return !empty($ret) && isset($ret[$service]) && !empty($ret[$service]) ?  true : false;
	}
}